package com.youhong.teethcare.settingpage;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.wx.wheelview.adapter.ArrayWheelAdapter;
import com.wx.wheelview.widget.WheelView;
import com.youhong.teethcare.R;
import com.youhong.teethcare.utils.ScreenUtils;

import java.util.ArrayList;
import java.util.List;

public class GenderActivity extends Activity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gender);
        int height = ScreenUtils.dip2px(this, 400);
        int width = ScreenUtils.getScreenWidth(this) - ScreenUtils.dip2px(this, 18);
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.width = width;
        layoutParams.height = height;
        layoutParams.gravity = Gravity.BOTTOM;
        layoutParams.verticalMargin = 0.02f;
        layoutParams.windowAnimations = R.style.dialog_bottom_animstyle;
       getWindow().setAttributes(layoutParams);
        getViews();
    }

    TextView tv_confirm;
    TextView tv_cancel;
    WheelView wv;

    private void getViews() {

        tv_confirm = (TextView) findViewById(R.id.gender_tv_confirm);
        tv_confirm.setOnClickListener(this);

        tv_cancel = (TextView) findViewById(R.id.gender_tv_cancel);
        tv_cancel.setOnClickListener(this);

        wv = (WheelView) findViewById(R.id.gender_wv);


        List<String> list = new ArrayList<>();

        list.add(getResources().getString(R.string.strings51));
        list.add(getResources().getString(R.string.strings52));

        wv.setWheelAdapter(new ArrayWheelAdapter(this)); // 文本数据源
        wv.setSkin(WheelView.Skin.Holo); // common皮肤
        wv.setWheelData(list);

        String gender = getIntent().getStringExtra("gender");
        if (gender != null) {


            if (gender.equals("1")) {

                wv.setSelection(0);

            } else {

                wv.setSelection(1);
            }
        }
    }

    @Override
    public void onClick(View v) {

        if (v == tv_confirm) {


            Intent return_intent = new Intent();

            //Male:1, female 2;
            if (wv.getCurrentPosition() == 0) {

                return_intent.putExtra("gender", "1");

            } else {

                return_intent.putExtra("gender", "2");

            }
            setResult(Activity.RESULT_OK, return_intent);
            this.finish();

        } else if (v == tv_cancel) {

            this.finish();
        }

    }
}

